package com.luoqiz.project.qq.server;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.luoqiz.project.qq.server.threads.BroadcastThread;
import com.luoqiz.project.qq.server.threads.ChatMainThread;


public class ServerAppMain extends JFrame {

	private static final long serialVersionUID = -3538194641522493910L;

	public static Map<String,Socket> sessionMap=new  HashMap<String,Socket>();

	public static JTextArea msgContentJta;

	public ServerAppMain() {
		this.setLayout(null);
		this.setBounds(100, 100, 900, 500);
		this.setTitle("服务器端");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		init();
	}

	private void init() {
		JButton startBtn = new JButton("开启服务器");
		startBtn.setBounds(600, 10, 150, 40);
		startBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println(e.getActionCommand());
				new ChatMainThread().start();
			}
		});
		this.add(startBtn);

		JTextField broadcastJtf = new JTextField();
		broadcastJtf.setBounds(520, 65, 200, 30);
		this.add(broadcastJtf);

		JButton broadcastBtn = new JButton("广播消息");
		broadcastBtn.setBounds(750, 65, 120, 30);
		broadcastBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new BroadcastThread(broadcastJtf.getText()).start();
				broadcastJtf.setText("");
			}
		});
		this.add(broadcastBtn);

		msgContentJta = new JTextArea();
		JScrollPane msgContentJsp = new JScrollPane(msgContentJta);
		msgContentJsp.setBounds(10, 10, 500, 400);
		this.add(msgContentJsp);
	}

	public static void main(String[] args) {
		new ServerAppMain();
	}

}
